<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="解封原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea
            v-decorator="['unsealReason', validatorRules.unsealReason]"
            placeholder="请输入解封原因"
            :autosize="{ minRows: 4 }"
          ></a-textarea>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import JDate from '@/components/jeecg/JDate'
import { putAction } from '../../../api/manage'

export default {
  name: 'SysLoginErrorModal',
  components: {
    JDate,
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 600,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        unsealReason: {rules: [{required: true, message: '请输入解封原因'}]},
      },
      url: {
        unsealBatch: '/system/sysLoginError/unsealBatch',    //批量解封接口
      },
      ids: ''
    }
  },
  methods: {
    edit(ids) {
      this.ids = ids
      this.form.resetFields()
      this.model = Object.assign({})
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(this.model, 'unsealReason')
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, values);
          putAction(that.url.unsealBatch + '?ids=' + that.ids + '&unsealReason=' + formData.unsealReason ).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  },
}
</script>